package com.example.workrecord.controller;

import com.alibaba.fastjson.JSONObject;
import com.example.workrecord.common.Page;
import com.example.workrecord.config.WebLog;
import com.example.workrecord.entity.CorpUserDetail;
import com.example.workrecord.entity.PlatForm;
import com.example.workrecord.exption.BizException;
import com.example.workrecord.service.PlatFormService;
import com.example.workrecord.util.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
  *@Description 平台成果手机端端接口
  *@Param
  *@Return
  *@Author Mr.Bu
  *@Date 2019/6/18
  *@Time 15:02
  */
@RestController
@Api(value = "platformmob", description = "平台成果手机端端接口", consumes = "application/json;charset=UTF-8")
@RequestMapping(value = "/platformmob")
public class PlatformMobController  extends BaseController {


    @Autowired
    private PlatFormService formService;

    @PostMapping("/list")
    @ResponseBody
    @WebLog(description = "分页查询Platform")
    @ApiOperation(value = "分页查询Platform，根据条件查询", notes = "{\"userId\": \"用户id\",\"limit\": \"分页大小，此参数代表分页大小，最大100\",\"offset\": \"分页偏移，默认值：0\",\"startDate\": \"开始时间\",\"endDate\": \"结束时间\",\"searchDate\": \"搜索\"}")
    public Result findUserByData(HttpServletRequest request, @RequestBody PlatForm vo ){
        Page<PlatForm> page =new Page<>();
        try{
//            CorpUserDetail user = getUserInfo(request);
//            if(null ==user ){
//                return Result.error("用户不可为空，请检查！");
//            }
            checkNull(vo,"参数不可为空！");
            page.setPageCurrent(vo.getOffset()+1);
            page.setPageSize(vo.getLimit());
            vo.setStatus(0);
            formService.findUserByData(vo,page);
        }catch (BizException e){
            return Result.error(e.getMessage());
        }
        return Result.success(page);
    }

    @PostMapping("/findById")
    @ResponseBody
    @WebLog(description = "根据Id查询Platform")
    @ApiOperation(value = "根据Id查询Platform", notes = "{\"id\":\"id\"}")
    public Result findById(HttpServletRequest request, @RequestBody JSONObject res ){
        PlatForm form=new PlatForm();
        try{
//            CorpUserDetail user = getUserInfo(request);
//            if(null ==user ){
//                return Result.error("用户不可为空，请检查！");
//            }
            checkNull(res,"参数不可为空");
            Integer id=res.getInteger("id");
            form.setId(Long.valueOf(id));
            form=formService.findPlatFormById(form);
        }catch (BizException e){
            return Result.error(e.getMessage());
        }
        return Result.success(form);
    }
}
